home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 34.zip / BS1 part 34 / FredFish PD 315.adf / Surf / getfilenames.c < prev    next >
C/C++ Source or Header  |  1990-02-14  |  4KB  |  223 lines

  1. #include <intuition/intuition.h>
  2. #include "scrnio.ih"
  3. #include <exec/memory.h>
  4. #ifdef MANX
  5. #include <functions.h>
  6. #endif
  7.  
  8. #include "scrndef.h"
  9. #include "mytypes.h"
  10.  
  11.  
  12. #define StringSize 40
  13. #define ROW 8
  14. #define COL 8
  15. #define TextX COL
  16. #define TextY (ROW/2)
  17. #define StringX 8
  18. #define StringY 12
  19. #define ReqSizeX 50*COL
  20. #define ReqSizeY 6*ROW
  21.  
  22. #define CodeGo 100
  23. #define CodeCancel 101
  24.  
  25. /*
  26.  * declarations for a cancel button to be used by both
  27.  * requestors.
  28.  */
  29. static struct IntuiText TextCancel = {
  30.     1,-1,JAM1, 2, 1, NULL,(UBYTE *) "Cancel", NULL };
  31.  
  32. static short S_Cancel[] = {
  33.     -2,-1,  -2,ROW+1,  6*COL+2,ROW+1,  6*COL+2,-1, -2,-1
  34.  };
  35.  
  36. static struct Border B_Cancel = { 0, 0, 1, 0, JAM1, 5, S_Cancel, NULL };
  37.  
  38. static struct Gadget G_Cancel = {
  39.     NULL,
  40.     10*COL, ROW *4, 6*COL, ROW, /* loc and size of hit box */
  41.     GADGHBOX,    /* complemented when pressed */
  42.     RELVERIFY,    /* just get gadget up messages */
  43.     BOOLGADGET | REQGADGET,
  44.     (APTR)&B_Cancel, NULL,
  45.     &TextCancel,
  46.     0, NULL,
  47.     (int)CodeCancel,
  48.     NULL
  49.  };
  50.  
  51. /*
  52.  * String gadget to get ilbm filename
  53.  */
  54. static char OutTitle[] = { "output filename:" };
  55. static char InTitle[] = { "input filename:" };
  56.  
  57. static struct IntuiText TextOutFile = {
  58.     1,1,JAM1, TextX, TextY, NULL,
  59.     (UBYTE *)OutTitle, NULL
  60.  };
  61. static struct IntuiText TextInFile = {
  62.     1,1,JAM1, TextX, TextY, NULL,
  63.     (UBYTE *)InTitle, NULL
  64.  };
  65.  
  66.  
  67. static char OutNameBuff[StringSize] = { "out.ilbm" };
  68. static char InNameBuff[StringSize] =  { "in.ilbm" };
  69. static char undo[StringSize];
  70.  
  71. static struct StringInfo S_OutFile = {
  72.     (UBYTE *)OutNameBuff,
  73.     (UBYTE *)undo,
  74.     0,
  75.     sizeof( OutNameBuff),
  76.     0,
  77.     0,
  78.     13,
  79.     0,
  80.     0,0,NULL,0, NULL
  81. };
  82.  
  83. static struct StringInfo S_InFile = {
  84.     (UBYTE *)InNameBuff,
  85.     (UBYTE *)undo,
  86.     0,
  87.     sizeof( InNameBuff),
  88.     0,
  89.     0,
  90.     13,
  91.     0,
  92.     0,0,NULL,0, NULL
  93. };
  94.  
  95. static short BD_InOut[] = {
  96.     -2,-1,  -2, ROW,  (StringSize-1)*COL+1,ROW,
  97.     (StringSize-1)*COL+1,-1, -2, -1
  98.  };
  99.  
  100. static struct Border B_InOut = { 0, 0, 1, 0, JAM1, 5, BD_InOut, NULL };
  101.  
  102. static struct Gadget G_OutFile = {
  103.     &G_Cancel,
  104.     StringX , StringY,   /* loc */
  105.     sizeof(OutNameBuff)*COL, ROW, /* size */
  106.     GADGHCOMP,
  107.     RELVERIFY /* | STRINGCENTER */,
  108.     STRGADGET | REQGADGET,
  109.     (APTR)&B_InOut, /* border */
  110.     NULL, /* high lighted */
  111.     &TextOutFile,
  112.     0,
  113.     (APTR) &S_OutFile,
  114.     (int)CodeGo,
  115.     NULL
  116.  };
  117.  
  118.  
  119. static struct Gadget G_InFile = {
  120.     &G_Cancel,
  121.     StringX , StringY,   /* loc */
  122.     sizeof(InNameBuff)*COL, ROW, /* size */
  123.     GADGHCOMP,
  124.     RELVERIFY/* | STRINGCENTER */,
  125.     STRGADGET | REQGADGET,
  126.     (APTR)&B_InOut, /* border */
  127.     NULL, /* high lighted */
  128.     NULL, /* text */
  129.     0,
  130.     (APTR) &S_InFile,
  131.     (int)CodeGo,
  132.     NULL
  133.  };
  134.  
  135. static struct Requester R_InFile = {
  136.     NULL,
  137.     COL*10, ROW*4, ReqSizeX, ReqSizeY,
  138.     0, 0,
  139.     &G_InFile,
  140.     NULL,
  141.     &TextInFile,
  142.     NULL,
  143.     2, /* backfill */
  144.     NULL,
  145.     { NULL },
  146.     { NULL },
  147.     NULL,
  148.     { NULL },
  149. };
  150.  
  151.  
  152.  
  153.  
  154. static struct Requester R_OutFile = {
  155.     NULL,
  156.     COL*10, ROW*4, ReqSizeX, ReqSizeY,
  157.     0, 0,
  158.     &G_OutFile,
  159.     NULL,
  160.     &TextOutFile,
  161.     NULL,
  162.     2, /* backfill */
  163.     NULL,
  164.     { NULL },
  165.     { NULL },
  166.     NULL,
  167.     { NULL },
  168. };
  169.  
  170. static bool
  171. WaitForUser() {
  172.     struct IntuiMessage mycopy,
  173.                         *orig;
  174.     long wakeupmask;
  175.  
  176.     for(;;) {
  177.         wakeupmask = Wait( 1<< CntrlWin->UserPort->mp_SigBit );
  178.  
  179.         /*
  180.          * handle messages for the control window
  181.          */
  182.  
  183.         while( orig =(struct IntuiMessage *) GetMsg( CntrlWin->UserPort ) ) {
  184.  
  185.             mycopy = *orig;
  186.             ReplyMsg( orig );
  187.  
  188.             if( mycopy.Class == GADGETUP ) {
  189.                 USHORT code;
  190.  
  191.                 code = ((struct Gadget*)mycopy.IAddress)->GadgetID;
  192.                 if( code == CodeGo ) return( true );
  193.                 if( code == CodeCancel) return(false);
  194.             }
  195.         }
  196.     }
  197. }
  198.  
  199.  
  200.  
  201. char *GetInFile()
  202. {
  203.     bool answer;
  204.     Request( &R_InFile, CntrlWin);
  205.     answer = WaitForUser();
  206.     EndRequest( &R_InFile, CntrlWin);
  207.     return( answer?InNameBuff: NULL);
  208. }
  209.  
  210.  
  211. char *GetOutFile()
  212. {
  213.     bool answer;
  214.     Request( &R_OutFile, CntrlWin);
  215.     answer = WaitForUser();
  216.     EndRequest( &R_OutFile, CntrlWin);
  217.     return( answer?OutNameBuff: NULL);
  218. }
  219.  
  220.  
  221.  
  222.  
  223.